//
//  RedPacketDetailViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/10/12.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "RedPacketDetailViewController.h"

#import "RedPacketDetailTableViewCell.h"

@interface RedPacketDetailViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;
//头视图
@property (nonatomic, strong) UIView * view_Head;
@property (nonatomic, strong) UIImageView * image_Head;
@property (nonatomic, strong) UIImageView * image_Pin;
@property (nonatomic, strong) UILabel * name;
@property (nonatomic, strong) UILabel * detail;
@property (nonatomic, strong) UILabel * money;
@property (nonatomic, strong) UILabel * money_detail;
@property (nonatomic, strong) UILabel * message_detail;

@end

@implementation RedPacketDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"XX红包";
    //250 94 98
    _topView.backgroundColor = [UIColor colorWithRed:251/255.0 green:78/255.0 blue:71/255.0 alpha:1.0f];
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 35, 15)];
    lbl_return.text = @"返回";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 60, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.showsVerticalScrollIndicator = NO;
    [self p_headView];
    self.tableView.tableHeaderView = self.view_Head;
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[RedPacketDetailTableViewCell class] forCellReuseIdentifier:@"cell_RedPacketDetail"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 11;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 65.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RedPacketDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_RedPacketDetail" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    cell.name.textColor = [UIColor blackColor];
    cell.money.textColor = [UIColor blackColor];
    cell.best.hidden = YES;
    
    if(indexPath.row == 1)
    {
        cell.name.textColor = [UIColor colorWithRed:250/255.0 green:176/255.0 blue:96/255.0 alpha:1.0f];
        cell.money.textColor = [UIColor colorWithRed:250/255.0 green:176/255.0 blue:96/255.0 alpha:1.0f];
        cell.best.hidden = NO;
    }
    
    return cell;
}

#pragma mark - 布局
- (void )p_headView
{
    self.view_Head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 313)];
    
    //红色背景
    UIImageView * image_TopBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, - 1030, SCREEN_WIDTH, 1100)];
    image_TopBG.backgroundColor = [UIColor colorWithRed:251/255.0 green:78/255.0 blue:71/255.0 alpha:1.0f];
    image_TopBG.layer.cornerRadius = 60;
    [self.view_Head addSubview:image_TopBG];
    
    //头像
    self.image_Head = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 45, 30, 90, 90)];
    self.image_Head.layer.cornerRadius = 45;
    self.image_Head.layer.masksToBounds = YES;
    self.image_Head.image = [UIImage imageNamed:@"heads.jpg"];
    [self.view_Head addSubview:self.image_Head];
    
    //姓名
    self.name = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.image_Head.frame) + 10, SCREEN_WIDTH - 20, 15)];
    self.name.text = @"XXX的红包";
    self.name.textColor = [UIColor blackColor];
    self.name.font = [UIFont systemFontOfSize:18.0f];
    self.name.textAlignment = NSTextAlignmentCenter;
    [self.view_Head addSubview:self.name];
    
    CGFloat length_xPin = [@"XXX的红包" boundingRectWithSize:CGSizeMake(1000, 15) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:17.0f]} context:nil].size.width;
    
    self.image_Pin = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + length_xPin / 2 + 8, CGRectGetMaxY(self.image_Head.frame) + 7.5, 20, 20)];
    self.image_Pin.layer.masksToBounds = YES;
    self.image_Pin.image = [UIImage imageNamed:@"Pin.png"];
    [self.view_Head addSubview:self.image_Pin];
    
    //
    self.detail = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.name.frame) + 13, SCREEN_WIDTH - 20, 15)];
    self.detail.text = @"谢谢大家---大家辛苦了";
    self.detail.textColor = [UIColor grayColor];
    self.detail.font = [UIFont systemFontOfSize:16.0f];
    self.detail.textAlignment = NSTextAlignmentCenter;
    [self.view_Head addSubview:self.detail];
    
    self.money = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.detail.frame) + 25, SCREEN_WIDTH - 20, 35)];
    self.money.text = @"0.83";
    self.money.font = [UIFont systemFontOfSize:35.0f];
    self.money.textAlignment = NSTextAlignmentCenter;
    [self.view_Head addSubview:self.money];
    
    CGFloat length_xMoney = [@"0.83" boundingRectWithSize:CGSizeMake(1000, 35) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:35.0f]} context:nil].size.width;
    
    UILabel * lbl_Yuan = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + length_xMoney / 2 + 2, CGRectGetMaxY(self.detail.frame) + 40, 20, 15)];
    lbl_Yuan.text = @"元";
    lbl_Yuan.font = [UIFont systemFontOfSize:17.0f];
    lbl_Yuan.textAlignment = NSTextAlignmentCenter;
    [self.view_Head addSubview:lbl_Yuan];
 
    self.money_detail = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.money.frame) + 15, SCREEN_WIDTH - 20, 15)];
    self.money_detail.textAlignment = NSTextAlignmentCenter;
    self.money_detail.text = @"已存入零钱,可直接提现";
    self.money_detail.font = [UIFont systemFontOfSize:15.0f];
    self.money_detail.textColor = [UIColor colorWithRed:90/255.0 green:167/255.0 blue:239/255.0 alpha:1.0];
    [self.view_Head addSubview:self.money_detail];
    
    UIView * view_bg = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.money_detail.frame) + 20, SCREEN_WIDTH, 30)];
    view_bg.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view_Head addSubview:view_bg];
    
    self.message_detail = [[UILabel alloc] initWithFrame:CGRectMake(15, 7.5,SCREEN_WIDTH - 30, 15)];
    self.message_detail.text = @"20个红包共20.00元,该红包已过期";
    self.message_detail.textColor = [UIColor grayColor];
    self.message_detail.font = [UIFont systemFontOfSize:14.0f];
    [view_bg addSubview:self.message_detail];
}


@end
